﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;

namespace SharpSoft.WPF.Controls
{
    partial class DocumentViewerExtension : ResourceDictionary
    {

        static DocumentViewerExtension()
        {
            _NextPageCommand = new RoutedUICommand("下一页",
               "NextPageCommand",
               typeof(DocumentViewer),
               null);
            CommandManager.RegisterClassCommandBinding(typeof(DocumentViewer), new CommandBinding(_NextPageCommand, new ExecutedRoutedEventHandler(OnNextPageCommandExecuted)));
            _PreviousPageCommand = new RoutedUICommand("上一页",
               "PreviousPageCommand",
               typeof(DocumentViewer),
               null);
            CommandManager.RegisterClassCommandBinding(typeof(DocumentViewer), new CommandBinding(_PreviousPageCommand, new ExecutedRoutedEventHandler(OnPreviousPageCommandExecuted)));
        }


        public static ScrollBarVisibility GetHorizontalScrollBarVisibility(DependencyObject obj)
        {
            return (ScrollBarVisibility)obj.GetValue(HorizontalScrollBarVisibilityProperty);
        }

        public static void SetHorizontalScrollBarVisibility(DependencyObject obj, ScrollBarVisibility value)
        {
            obj.SetValue(HorizontalScrollBarVisibilityProperty, value);
        }

        public static readonly DependencyProperty HorizontalScrollBarVisibilityProperty =
            DependencyProperty.RegisterAttached("HorizontalScrollBarVisibility", typeof(ScrollBarVisibility), typeof(DocumentViewerExtension), new PropertyMetadata(ScrollBarVisibility.Hidden));



        public static ScrollBarVisibility GetVerticalScrollBarVisibility(DependencyObject obj)
        {
            return (ScrollBarVisibility)obj.GetValue(VerticalScrollBarVisibilityProperty);
        }

        public static void SetVerticalScrollBarVisibility(DependencyObject obj, ScrollBarVisibility value)
        {
            obj.SetValue(VerticalScrollBarVisibilityProperty, value);
        }

        public static readonly DependencyProperty VerticalScrollBarVisibilityProperty =
            DependencyProperty.RegisterAttached("VerticalScrollBarVisibility", typeof(ScrollBarVisibility), typeof(DocumentViewerExtension), new PropertyMetadata(ScrollBarVisibility.Hidden));





        /// <summary>
        /// 获取文档查看器是否显示翻页按钮
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static bool GetPagingButtonVisible(DependencyObject obj)
        {
            return (bool)obj.GetValue(PagingButtonVisibleProperty);
        }
        /// <summary>
        /// 设置文档查看器是否显示翻页按钮
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="value"></param>
        public static void SetPagingButtonVisible(DependencyObject obj, bool value)
        {
            obj.SetValue(PagingButtonVisibleProperty, value);
        }

        public static readonly DependencyProperty PagingButtonVisibleProperty =
           DependencyProperty.RegisterAttached("PagingButtonVisible", typeof(bool), typeof(DocumentViewerExtension), new PropertyMetadata(true));




        #region 指令扩展

        private static RoutedUICommand _NextPageCommand;
        /// <summary>
        /// 下一页指令
        /// </summary>
        public static RoutedUICommand NextPageCommand
        {

            get
            {
                return _NextPageCommand;
            }
        }

        private static RoutedCommand _PreviousPageCommand;
        /// <summary>
        /// 上一页指令
        /// </summary>
        public static RoutedCommand PreviousPageCommand
        {
            get { return _PreviousPageCommand; }
        }

        private static void OnPreviousPageCommandExecuted(object sender, ExecutedRoutedEventArgs e)
        {
            if (sender is System.Windows.Controls.Primitives.DocumentViewerBase dv)
            {
                if (dv.CanGoToPreviousPage)
                {
                    dv.PreviousPage();
                }
            }
        }

        private static void OnNextPageCommandExecuted(object sender, ExecutedRoutedEventArgs e)
        {
            if (sender is System.Windows.Controls.Primitives.DocumentViewerBase dv)
            {
                if (dv.CanGoToNextPage)
                {
                    dv.NextPage();
                }
            }
        }
        #endregion

        #region handler
        public void OnPreviewMouseLeftButtonDown(object sender, RoutedEventArgs e)
        {//阻断鼠标左键按下事件
            e.Handled = true;
        }

        public void OnPreviewMouseWheel(object sender, RoutedEventArgs e)
        {//阻断滚轮事件
            e.Handled = true;
        }
        #endregion
    }
}
